/*
 * Copyright (c) 2010 MoSync AB
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include <wchar.h>
#include <conprint.h>

#include <MAInterpreter/System.h>

#include "BrowserMoblet.h"
#include "BrowserScreen.h"
#include "MyTextBoxListener.h"

#include "MAHeaders.h"

BrowserMoblet::BrowserMoblet()
{
	initializeFonts();
	browserScreen = new BrowserScreen(this);
	browserScreen->show();
}

BrowserMoblet::~BrowserMoblet()
{
	if (browserScreen)
	{
		delete browserScreen;
		browserScreen = NULL;
	}
}

void BrowserMoblet::customEvent(const MAEvent& event)
{
	if (EVENT_TYPE_TEXTBOX == event.type && MA_TB_RES_OK == event.textboxResult)
	{
		/*char dst[512];

		wcstombs(dst, ,
		size_t 	count
		)
		lprintfln()
		*/
		lprintfln("Calling handleTextBoxResult");
		//maUpdateScreen();

		if (NULL != textBoxListener)
		{
			lprintfln("Calling handleTextBoxResult 2");
			textBoxListener->handleTextBoxResult(event.textboxLength);
		}
	}
}

void BrowserMoblet::setTextBoxListener(MyTextBoxListener* listener)
{
	textBoxListener = listener;
}

void BrowserMoblet::initializeFonts()
{
	Sys()->addFont("Arial16White", ARIAL16WHITE);
	Sys()->addFont("Arial16BoldWhite", ARIAL16WHITE);
	Sys()->addFont("Arial16Black", ARIAL16BLACK);
	Sys()->addFont("Arial16BoldBlack", ARIAL16BOLDBLACK);
	Sys()->addFont("Arial20White", ARIAL20WHITE);
	Sys()->addFont("Arial20BoldWhite", ARIAL20WHITE);
	Sys()->addFont("Arial20Black", ARIAL20BLACK);
	Sys()->addFont("Arial20BoldBlack", ARIAL20BOLDBLACK);
	Sys()->addFont("Arial32White", ARIAL32WHITE);
	Sys()->addFont("Arial32BoldWhite", ARIAL32BOLDWHITE);
	Sys()->addFont("Arial32Black", ARIAL32BLACK);
	Sys()->addFont("Arial32BoldBlack", ARIAL32BOLDBLACK);
	Sys()->addFont("Arial40White", ARIAL40WHITE);
	Sys()->addFont("Arial40BoldWhite", ARIAL40BOLDWHITE);
	Sys()->addFont("Arial40Black", ARIAL40BLACK);
	Sys()->addFont("Arial40BoldBlack", ARIAL40BOLDBLACK);
}

